﻿using System;

namespace RotovapPlatform.Domain.Equipment.Interfaces.Base
{
	/// <summary>
	/// IO信号接口，定义IO信号的基本属性
	/// </summary>
	public interface IIOSignal
	{
		/// <summary>
		/// 信号ID
		/// </summary>
		string Id { get; }

		/// <summary>
		/// 信号名称
		/// </summary>
		string Name { get; }

		/// <summary>
		/// 信号描述
		/// </summary>
		string Description { get; }

		/// <summary>
		/// 信号状态变化事件
		/// </summary>
		event EventHandler<IOSignalStateChangedEventArgs> StateChanged;
	}

	/// <summary>
	/// 数字输入信号接口
	/// </summary>
	public interface IDISignal : IIOSignal
	{
		/// <summary>
		/// 当前状态值
		/// </summary>
		bool State { get; }

		/// <summary>
		/// 信号通道编号
		/// </summary>
		int Channel { get; }
	}

	/// <summary>
	/// 数字输出信号接口
	/// </summary>
	public interface IDOSignal : IIOSignal
	{
		/// <summary>
		/// 当前状态值
		/// </summary>
		bool State { get; }

		/// <summary>
		/// 信号通道编号
		/// </summary>
		int Channel { get; }

		/// <summary>
		/// 设置信号状态
		/// </summary>
		/// <param name="state">状态值</param>
		/// <returns>操作是否成功</returns>
		Task<bool> SetStateAsync(bool state);
	}

	/// <summary>
	/// 模拟输入信号接口
	/// </summary>
	public interface IAISignal : IIOSignal
	{
		/// <summary>
		/// 当前模拟值
		/// </summary>
		double Value { get; }

		/// <summary>
		/// 信号通道编号
		/// </summary>
		int Channel { get; }

		/// <summary>
		/// 信号量程下限
		/// </summary>
		double MinValue { get; }

		/// <summary>
		/// 信号量程上限
		/// </summary>
		double MaxValue { get; }

		/// <summary>
		/// 信号单位
		/// </summary>
		string Unit { get; }
	}

	/// <summary>
	/// IO信号状态变化事件参数
	/// </summary>
	public class IOSignalStateChangedEventArgs : EventArgs
	{
		/// <summary>
		/// 信号ID
		/// </summary>
		public string SignalId { get; }

		/// <summary>
		/// 之前的状态
		/// </summary>
		public object OldState { get; }

		/// <summary>
		/// 当前状态
		/// </summary>
		public object NewState { get; }

		/// <summary>
		/// 构造函数
		/// </summary>
		public IOSignalStateChangedEventArgs(string signalId, object oldState, object newState)
		{
			SignalId = signalId;
			OldState = oldState;
			NewState = newState;
		}
	}
}